package com.bridgeintelligent.tag.webserver.dim.mgmt.service.dim;

import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DimRep;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.model.DimNumModel;
import com.bridgeintelligent.tag.webserver.dim.mgmt.service.dim.vo.DimVO;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;

/**
 * Created by JackCheung on 2019/9/9 10:09 PM.
 */
public interface IDimService {

    default <T> void fatherToChild(T father, T child) throws Exception {
        Class<?> fatherClass = father.getClass();
        Field[] declaredFields = fatherClass.getDeclaredFields();
        for (Field field : declaredFields) {
            Method method;
            if (field.getType() == boolean.class) {
                if (isUp(field.getName())) {
                    method = fatherClass.getDeclaredMethod(field.getName());
                } else {
                    method = fatherClass.getDeclaredMethod("is" + upperHeadChar(field.getName()));
                }
            } else {
                method = fatherClass.getDeclaredMethod("get" + upperHeadChar(field.getName()));
            }
            Object obj = method.invoke(father);
            field.setAccessible(true);
            field.set(child, obj);
        }
    }

    default boolean isUp(String in) {
        for (int i = 0; i < in.length(); i++) {
            char c = in.charAt(i);
            if (Character.isUpperCase(c)) {
                return true;
            }
        }
        return false;
    }

    default String upperHeadChar(String in) {
        String head = in.substring(0, 1);
        return head.toUpperCase() + in.substring(1, in.length());
    }

    DimRep detail(String dimId);

    DimRep add(String dimJson);

    DimRep addEntity(DimVO dimVO);

    DimRep start(String state, String dimId);

    DimRep update(String dimJson);

    DimRep updateEntity(DimVO dimVO);

    DimRep list(Integer pageNumber, Integer pageSize, String theme, String dimName, String department, String state, String createTimeStart, String createTimeEnd, String uptTimeStart, String uptTimeEnd, String catalogId, String businessDepartment);

    DimRep del(String dimId);

    DimRep inCatalogList(String dimName);

    //基础标签列表
    DimRep dimList(Integer pageNumber, Integer pageSize, String theme, String dimName, String department, String state, String createTimeStart, String createTimeEnd, String uptTimeStart, String uptTimeEnd, String catalogId, String businessDepartment);

    DimRep esTimeData();

    DimRep esTimeOutput();

    DimRep esTimeLast();

    //删除组合标签相关的数据
    void delCombinationInfo(String combinationId);

    DimRep stop(String dimId);

    /**
     * 新版-获取ES最新日期
     * @return
     */
    DimRep newEsTime(String indexId);

    /**
     * 获取日期跟固定标识的映射关系
     * @return
     */
    DimRep mapEsTime(String indexId);

    /**
     * 获取数值型标签
     * @param dimName
     * @param dimId
     * @return
     */
    List<DimNumModel> numberDimList(String dimName,String dimId,String indexId);
}
